package com.gxa.learning.pc.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.learning.core.common.JsonResult;
import com.gxa.learning.core.pojo.Department;
import com.gxa.learning.pc.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author lijianmin
 * @date 2021/12/07  20:27:32
 */
@RestController
@RequestMapping("/department")
@Api(tags = "部门的接口")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 根据公司编号获取公司的所有的部门
     *
     * @param id 公司编号
     * @return 返回查询到的部门信息
     * @throws IllegalAccessException 操作中产生的异常
     */
    @GetMapping("/selectById")
    @ApiOperation("根据公司id查询所属的部门")
    @ApiImplicitParam(name = "id", value = "公司的编号", paramType = "query")
    public Map<String, Object> selectById(@RequestParam("id") Long id) throws IllegalAccessException {
        Department department = new Department();
        department.setCompanyId(id);
        PageInfo<Department> departmentPageInfo = departmentService.selectByPageEquals(null, null, department);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(departmentPageInfo.getList());
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.put("count", departmentPageInfo.getTotal());
        return jsonResult.getDataMap();
    }

}
